package model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

/**
 * The persistent class for the passenger database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name= "Passenger.findPassengerByLogin", query="select p from Passenger p where p.login = :login"),
	@NamedQuery(name= "Passenger.findPassengerByNameSurname", query="select p from Passenger p where p.passengerName = :name " +
			"AND p.passengerSurname = :surname")
})
public class Passenger implements Serializable {
	
	public static final String FIND_BY_LOGIN = "Passenger.findPassengerByLogin";
	public static final String FIND_BY_NAME_SURNAME = "Passenger.findPassengerByNameSurname";
	
	private static final long serialVersionUID = 1L; 
	
	@Id
	private int passengerID = Math.abs(UUID.randomUUID().hashCode());

	private String login;
	
	private int enabled = 1;


	@Temporal(TemporalType.DATE)
	private Date passengerDateOfBirth;

	private String passengerName;

	private String passengerSurname;

	private String password;
	
	private int version;

	@Version
	public int getVersion() {
		return version;
	}

	@Version
	public void setVersion(int version) {
		this.version = version;
	}

	// bi-directional many-to-one association to Ticket
	@OneToMany(mappedBy = "passenger", cascade = CascadeType.ALL, orphanRemoval = true)
	private List<Ticket> tickets;

	public Passenger() {
	}

	public int getPassengerID() {
		return this.passengerID;
	}

	public void setPassengerID(int passengerID) {
		this.passengerID = passengerID;
	}

	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public Date getPassengerDateOfBirth() {
		return this.passengerDateOfBirth;
	}

	public void setPassengerDateOfBirth(Date passengerDateOfBirth) {
		this.passengerDateOfBirth = passengerDateOfBirth;
	}

	public String getPassengerName() {
		return this.passengerName;
	}

	public void setPassengerName(String passengerName) {
		this.passengerName = passengerName;
	}


	public String getPassengerSurname() {
		return this.passengerSurname;
	}

	public void setPassengerSurname(String passengerSurname) {
		this.passengerSurname = passengerSurname;
	}

	
	public String getPassword() {
		return this.password; 
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<Ticket> getTickets() {
		return this.tickets;
	}

	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	public String toString() {
		return "Passenger - Id: " + passengerID + ", First name: " + passengerName
				+ ", Last name: " + passengerSurname + ", Birthday: " + passengerDateOfBirth;
	}

	public int getEnabled() {
		return enabled;
	}

	public void setEnabled(int enabled) {
		this.enabled = enabled;
	}
}